package com.edu.exam.enums.assessment;

/**
 * 提交方式枚举
 *
 * @author System
 * @version 1.0.0
 */
public enum SubmissionMethod {
    ONLINE("ONLINE", "在线提交"),
    OFFLINE("OFFLINE", "线下提交"),
    EMAIL("EMAIL", "邮件提交"),
    SYSTEM("SYSTEM", "系统提交"),
    PAPER("PAPER", "纸质提交"),
    USB("USB", "U盘提交"),
    FTP("FTP", "FTP上传"),
    CLOUD("CLOUD", "云存储提交"),
    QR_CODE("QR_CODE", "扫码提交"),
    FACE_TO_FACE("FACE_TO_FACE", "当面提交");

    private final String code;
    private final String description;

    SubmissionMethod(String code, String description) {
        this.code = code;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据代码获取枚举值
     *
     * @param code 代码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果代码无效
     */
    public static SubmissionMethod fromCode(String code) {
        for (SubmissionMethod method : SubmissionMethod.values()) {
            if (method.code.equals(code)) {
                return method;
            }
        }
        throw new IllegalArgumentException("Unknown submission method code: " + code);
    }

    /**
     * 根据描述获取枚举值
     *
     * @param description 描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述无效
     */
    public static SubmissionMethod fromDescription(String description) {
        for (SubmissionMethod method : SubmissionMethod.values()) {
            if (method.description.equals(description)) {
                return method;
            }
        }
        throw new IllegalArgumentException("Unknown submission method description: " + description);
    }

    @Override
    public String toString() {
        return description;
    }
}